<template>
  <div class="login-container">
    <el-card class="login-box">
      <h2 style="text-align: center">系统登录</h2>
      <el-form
              :model="form"
              :rules="rules"
              ref="loginForm"
              label-width="0"
      >
        <el-form-item prop="username">
          <el-input
                  v-model="form.username"
                  placeholder="用户名"
                  prefix-icon="el-icon-user"
          ></el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input
                  v-model="form.password"
                  type="password"
                  placeholder="密码"
                  prefix-icon="el-icon-lock"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button
                  type="primary"
                  @click="handleLogin"
                  style="width: 100%"
          >
            登录
          </el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
  export default {
    name: 'LoginView',
    data() {
      return {
        form: {
          username: '',
          password: ''
        },
        rules: {
          username: [
            { required: true, message: '请输入用户名', trigger: 'blur' }
          ],
          password: [
            { required: true, message: '请输入密码', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      handleLogin() {
        this.$refs.loginForm.validate(valid => {
          if (valid) {
            // 模拟登录
            localStorage.setItem('token', 'demo-token')
            this.$router.push('/')
          }
        })
      }
    }
  }
</script>

<style scoped>
  .login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    background: #f0f2f5;
  }
  .login-box {
    width: 400px;
    padding: 20px;
  }
</style>
